package cn.zshprint.serein.service.impl;

import cn.zshprint.serein.service.UploadService;
import cn.zshprint.serein.utils.UploadUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.util.ArrayList;
import java.util.List;

/**
 * impl上传服务
 *
 * @author zshprint
 * @date 2021/07/28
 */
@Service
@Slf4j
public class UploadServiceImpl implements UploadService {

    /**
     * 上传跑龙套
     */
    @Autowired
        private UploadUtils uploadUtils;

    /**
     * 获取url
     *
     * @param multipartFile 多部分文件
     * @return {@link String}
     */
    @Override
        public String getUrl(MultipartFile multipartFile) {
            String url = uploadUtils.uploadDocument(multipartFile);
            log.info("url是{}", url);
            return url;
        }

    /**
     * 得到的url
     *
     * @param files 文件
     * @return {@link List<String>}
     */
    @Override
        public List<String> getUrls(MultipartFile[] files) {
            List<String> res = new ArrayList<>();
            for (MultipartFile file : files) {
                String s = uploadUtils.uploadDocument(file);
                res.add(s);
            }
            return res;
        }

}
